package adfc2.render3d.mesh;

import adfc2.render3d.TextureReference;
import adfc2.render3d.Utils;

import javax.media.opengl.GL;

public class SimpleQuads extends Primitive {
    public SimpleQuads(double[] color, double[] vertices, TextureReference texture) {
        super(GL.GL_QUADS, color, vertices, genTexcoord(vertices), genNormals(vertices), texture);
    }

    private static double[] genNormals(double[] vertices) {
        double[] normals = new double[vertices.length];
        for (int i = 0; i < vertices.length; i += 3 * 4) {
            Utils.normal(vertices, i, normals, i, 3 * 4);
        }
        return normals;
    }

    static double[] TEXCOORD = {
            0, 0,//bottom left
            1, 0,//bottom right
            1, 1,//top right
            0, 1//top left
    };

    private static double[] genTexcoord(double[] vertices) {
        double[] texcoord = new double[vertices.length * 2 / 3];
        for (int i = 0; i < texcoord.length; i += TEXCOORD.length) {
            System.arraycopy(TEXCOORD, 0, texcoord, i, TEXCOORD.length);
        }
        return texcoord;
    }


}
